Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix collection shift less than one item #51686

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

faissaloux
Copy link
Contributor

@faissaloux faissaloux commented Jun 2, 2024

Helloo 👋🏻

In this PR I have fixed the collection shift() behaviour when trying to shift less than one item.

Fixes #51684


$count = 0

Current

$collection = new Collection(['foo', 'bar', 'baz']);
echo $collection->shift(0); // ['foo', 'bar']
echo $collection; // ['baz']

Expected

$collection = new Collection(['foo', 'bar', 'baz']);
echo $collection->shift(0); // []
echo $collection; // ['foo', 'bar', 'baz']

$count < 0

Current

$collection = new Collection(['foo', 'bar', 'baz']);
echo $collection->shift(-1); // ['foo', 'bar', 'baz']
echo $collection; // []

Expected

$collection = new Collection(['foo', 'bar', 'baz']);
echo $collection->shift(-1); // InvalidArgumentException

@faissaloux faissaloux changed the title [10.x] Fix collection shift less than 1 [10.x] Fix collection shift less than one item Jun 2, 2024
@taylorotwell taylorotwell merged commit 8154eb6 into laravel:10.x Jun 3, 2024
24 checks passed
@faissaloux faissaloux deleted the fix-collection-shift branch June 3, 2024 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants